/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author ori
 */
@Entity
@Table(name = "Transportation")
@NamedQueries({
    @NamedQuery(name = "Transportation.findByDirection", query = "SELECT t FROM Transportation t WHERE (t.waypoint1 = :point AND t.direction1 = :dir) " +
    "OR (t.waypoint2 = :point AND t.direction2 = :dir)"),
    @NamedQuery(name = "Transportation.findAll", query = "SELECT t FROM Transportation t"),
    @NamedQuery(name = "Transportation.findByWaypoint1", query = "SELECT t FROM Transportation t WHERE t.transportationPK.waypoint1 = :waypoint1"),
    @NamedQuery(name = "Transportation.findByWaypoint2", query = "SELECT t FROM Transportation t WHERE t.transportationPK.waypoint2 = :waypoint2"),
    @NamedQuery(name = "Transportation.findByTransportType", query = "SELECT t FROM Transportation t WHERE t.transportationPK.transportType = :transportType"),
    @NamedQuery(name = "Transportation.findByDistance", query = "SELECT t FROM Transportation t WHERE t.distance = :distance")})
public class Transportation implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TransportationPK transportationPK;
    @Basic(optional = false)
    @Column(name = "distance")
    private double distance;
    @JoinColumn(name = "waypoint1", referencedColumnName = "waypointid", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Waypoint waypoint1;
    @JoinColumn(name = "waypoint2", referencedColumnName = "waypointid", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Waypoint waypoint2;
    @JoinColumn(name = "transportType", referencedColumnName = "transportType", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private TransportationType transportationType;
    @JoinColumn(name = "direction1", referencedColumnName = "direction")
    @ManyToOne(optional = false)
    private Compass direction1;
    @JoinColumn(name = "direction2", referencedColumnName = "direction")
    @ManyToOne(optional = false)
    private Compass direction2;

    public Transportation() {
    }

    public Transportation(TransportationPK transportationPK) {
        this.transportationPK = transportationPK;
    }

    public Transportation(TransportationPK transportationPK, double distance) {
        this.transportationPK = transportationPK;
        this.distance = distance;
    }

    public Transportation(int waypoint1, int waypoint2, String transportType) {
        this.transportationPK = new TransportationPK(waypoint1, waypoint2, transportType);
    }

    public TransportationPK getTransportationPK() {
        return transportationPK;
    }

    public void setTransportationPK(TransportationPK transportationPK) {
        this.transportationPK = transportationPK;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public Waypoint getWaypoint() {
        return waypoint1;
    }

    public void setWaypoint(Waypoint waypoint) {
        this.waypoint1 = waypoint;
    }

    public Waypoint getWaypoint3() {
        return waypoint2;
    }

    public void setWaypoint3(Waypoint waypoint3) {
        this.waypoint2 = waypoint3;
    }

    public TransportationType getTransportationType() {
        return transportationType;
    }

    public void setTransportationType(TransportationType transportationType) {
        this.transportationType = transportationType;
    }

    public Compass getDirection1() {
        return direction1;
    }

    public void setDirection1(Compass direction1) {
        this.direction1 = direction1;
    }

    public Compass getDirection2() {
        return direction2;
    }

    public void setDirection2(Compass direction2) {
        this.direction2 = direction2;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (transportationPK != null ? transportationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Transportation)) {
            return false;
        }
        Transportation other = (Transportation) object;
        if ((this.transportationPK == null && other.transportationPK != null) || (this.transportationPK != null && !this.transportationPK.equals(other.transportationPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Transportation[transportationPK=" + transportationPK + "]";
    }

}
